package com.totoro.domain.key;

import java.io.Serializable;

import javax.persistence.CascadeType;
import javax.persistence.Embeddable;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;

import com.totoro.domain.Major;
import com.totoro.domain.Project;

//限选专业主键实体类
@Embeddable
public class AcceptableMajorKey implements Serializable {


	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@ManyToOne(cascade = { CascadeType.ALL })
	@JoinColumn(name = "major_id", referencedColumnName = "id")
	private Major major;// 专业

	@ManyToOne(cascade = { CascadeType.ALL })
	@JoinColumn(name = "project_id", referencedColumnName = "id")
	private Project project;// 毕业设计

	// 空构造器
	public AcceptableMajorKey() {
	}

	public Major getMajor() {
		return major;
	}

	public void setMajor(Major major) {
		this.major = major;
	}

	public Project getProject() {
		return project;
	}

	public void setProject(Project project) {
		this.project = project;
	}

	//复写hashCode方法
	@Override
	public int hashCode() {
		return getProject().getId() * 13 + getMajor().getId();
	}

	//复写equals方法
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj != null && this.getClass() == obj.getClass()) {
			AcceptableMajorKey target = (AcceptableMajorKey) obj;
			if (getMajor().getId().equals(target.getMajor().getId())
					&& getProject().getId().equals(target.getProject().getId()))
				return true;
		}
		return true;
	}

}
